import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { DataEvent } from "../../events/DataEvent";
import { ViewEvent } from "../../../mvc/events/ViewEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { SMyScore } from "../../../../Message/Public/SMyScore";
import { Language } from "../../../../extend/language/Language";
import { SAttribute } from "../../../../Message/Public/SAttribute";
import { ClockManager } from "../../manager/ClockManager";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { Global } from "../../../../com/gengine/global/Global";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { ObjCreate } from "../common/ObjCreate";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ResFileConst } from "../../resource/ResFileConst";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class BattleMiniScoreView
    
    export  class BattleMiniScoreView extends View
    {
        constructor()
        {
            super();
            layer = LayerManager.uiLayer;
            this.resetPos();
            this.createChildren();
            this.addListeners();
            return;
        }

        /* internal  */stageResize(arg1: DataEvent): void
        {
            this.resetPos();
            return;
        }

        /* internal  */onHide(arg1: ViewEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BattlefieldShowOrHideTop, false));
            return;
        }

        /* internal  */onMoveBtnMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._spMiniScore.startDrag();
            return;
        }

        /* internal  */onMoveBtnMouseUp(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._spMiniScore.stopDrag();
            return;
        }

        /* internal  */onClickShowScore(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BattlefieldAutoShowOrHideTop));
            return;
        }

        /* internal  */onClickUp(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._btnUp.parent) 
            {
                this._btnUp.parent.removeChild(this._btnUp);
            }
            this._spMiniScore.addChild(this._btnDown);
            if (this._spExtend.parent) 
            {
                this._spExtend.parent.removeChild(this._spExtend);
            }
            return;
        }

        /* internal  */onClickDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._btnDown.parent) 
            {
                this._btnDown.parent.removeChild(this._btnDown);
            }
            this._spMiniScore.addChild(this._btnUp);
            this._spMiniScore.addChild(this._spExtend);
            return;
        }

        public updateMyScore(arg1: SMyScore): void
        {
            this._tfMyKill.text = Language.getStringByParam(41623, arg1.killPlayer.toString());
            this._tfMyHonor.text = Language.getStringByParam(41624, arg1.honor.toString());
            return;
        }

        public updateCampScore(arg1: int, arg2: int, arg3: int): void
        {
            var loc1=0;
            var loc2=null;
            var loc5=0;
            this._tfCamp1Score.text = Language.getStringByParam(41626, arg1.toString());
            this._tfCamp2Score.text = Language.getStringByParam(41626, arg2.toString());
            this._tfCamp3Score.text = Language.getStringByParam(41626, arg3.toString());
            loc2 = [1, 2, 3];
            var loc3=[arg1, arg2, arg3];
            var loc4=0;
            while (loc4 < (loc3.length - 1)) 
            {
                loc5 = (loc3.length - 1);
                while (loc5 > loc4) 
                {
                    if (loc3[loc5] > loc3[(loc5 - 1)]) 
                    {
                        loc1 = loc2[loc5];
                        loc2[loc5] = loc2[(loc5 - 1)];
                        loc2[(loc5 - 1)] = loc1;
                        loc1 = loc3[loc5];
                        loc3[loc5] = loc3[(loc5 - 1)];
                        loc3[(loc5 - 1)] = loc1;
                    }
                    --loc5;
                }
                ++loc4;
            }
            this._tfCamp1Score.y = this.getScorePos(1, loc2);
            this._tfCamp2Score.y = this.getScorePos(2, loc2);
            this._tfCamp3Score.y = this.getScorePos(3, loc2);
            this._tfCamp1.y = this.getScorePos(1, loc2);
            this._tfCamp2.y = this.getScorePos(2, loc2);
            this._tfCamp3.y = this.getScorePos(3, loc2);
            this._tfUnion1.y = this.getScorePos(1, loc2);
            this._tfUnion2.y = this.getScorePos(2, loc2);
            this._tfUnion3.y = this.getScorePos(3, loc2);
            return;
        }

        /* internal  */getScorePos(arg1: int, arg2: Array<any>): int
        {
            if (arg1 == arg2[0]) 
            {
                return 50;
            }
            if (arg1 == arg2[1]) 
            {
                return 70;
            }
            return 90;
        }

        public updateUnionState(arg1: SAttribute): void
        {
            if (arg1.value == 0) 
            {
                this.isShowUnion1(false);
                this.isShowUnion2(false);
                this.isShowUnion3(false);
            }
            if (arg1.value == 1) 
            {
                this.isShowUnion1(false);
                this.isShowUnion2(true);
                this.isShowUnion3(true);
            }
            if (arg1.value == 2) 
            {
                this.isShowUnion1(true);
                this.isShowUnion2(false);
                this.isShowUnion3(true);
            }
            if (arg1.value == 3) 
            {
                this.isShowUnion1(true);
                this.isShowUnion2(true);
                this.isShowUnion3(false);
            }
            return;
        }

        /* internal  */isShowUnion1(arg1: Boolean): void
        {
            if (this._tfUnion1.parent && !arg1) 
            {
                this._tfUnion1.parent.removeChild(this._tfUnion1);
            }
            else if (arg1) 
            {
                this._spExtend.addChild(this._tfUnion1);
            }
            return;
        }

        /* internal  */isShowUnion2(arg1: Boolean): void
        {
            if (this._tfUnion2.parent && !arg1) 
            {
                this._tfUnion2.parent.removeChild(this._tfUnion2);
            }
            else if (arg1) 
            {
                this._spExtend.addChild(this._tfUnion2);
            }
            return;
        }

        /* internal  */isShowUnion3(arg1: Boolean): void
        {
            if (this._tfUnion3.parent && !arg1) 
            {
                this._tfUnion3.parent.removeChild(this._tfUnion3);
            }
            else if (arg1) 
            {
                this._spExtend.addChild(this._tfUnion3);
            }
            return;
        }

        public startCountdown(arg1: Date): void
        {
            this._endDate = arg1;
            var loc1=new Date(this._endDate.time - ClockManager.instance.nowDate.time);
            var loc2=Math.ceil(loc1.time / 1000);
            if (this._secTimer) 
            {
                this._secTimer.reset();
                this._secTimer.repeatCount = loc2;
            }
            else 
            {
                this._secTimer = new SecTimer(1, loc2);
            }
            this._secTimer.start();
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimeChange);
            return;
        }

        /* internal  */onTimeChange(arg1: SecTimer): void
        {
            var loc1=arg1.repeatCount;
            this._tfCountdown.text = Language.getStringByParam(41697, int(loc1 / 60).toString(), (loc1 % 60).toString());
            return;
        }

        public stopCountDown(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
            }
            this._secTimer = null;
            return;
        }

        public resetPos(): void
        {
            this.x = Global.stage.stageWidth - 190;
            this.y = 194;
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc7=null;
            this._spMiniScore = new Object /* flash.display.Sprite */();
            this._spMiniScore.mouseEnabled = false;
            this._spMiniScore.x = 0;
            this.addChild(this._spMiniScore);
            loc1 = new GTextFormat(FontUtil.songtiName, 12, 13563133);
            loc2 = new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(1).intColor);
            loc3 = new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(2).intColor);
            loc4 = new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(3).intColor);
            loc5 = new GTextFormat(FontUtil.songtiName, 12, 16711680);
            this._moveBtn = ObjCreate.createGButton("", 134, 0, 26, 23, this._spMiniScore, "MoveBtn");
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(41622), "#FFFFFF");
            var loc6;
            (loc6 = GlobalClass.getBitmap(ImagesConst.BattlefieldIconBgRight)).x = 86;
            loc6.y = 0;
            this._spMiniScore.addChild(loc6);
            this._btnShowScore = ObjCreate.createGLoadedButton(ResFileConst.BattleFieldResult, 0, 0, 114, 26, this._spMiniScore);
            this._btnUp = ObjCreate.createGButton("", 110, 0, 24, 25, this._spMiniScore, "BattlefieldIconUpBtn");
            this._btnDown = ObjCreate.createGButton("", 110, 0, 24, 25, null, "BattlefieldIconDownBtn");
            this._spExtend = new Object /* flash.display.Sprite */();
            this._spExtend.mouseEnabled = false;
            this._spExtend.mouseChildren = false;
            this._spMiniScore.addChild(this._spExtend);
            (loc7 = new Object /* flash.display.Bitmap */(new Object /* flash.display.BitmapData */(160, 106, false, 0))).alpha = 0.45;
            loc7.x = 0;
            loc7.y = 26;
            this._spExtend.addChild(loc7);
            this._tfMyKill = ObjCreate.createTextField(Language.getStringByParam(41623, "0"), 23, 30, 60, 20, this._spExtend, loc1);
            this._tfMyHonor = ObjCreate.createTextField(Language.getStringByParam(41624, "0"), 83, 30, 80, 20, this._spExtend, loc1);
            this._tfUnion1 = ObjCreate.createTextField(Language.getString(41625), 15, 50, 28, 20, null, loc5);
            this._tfUnion2 = ObjCreate.createTextField(Language.getString(41625), 15, 50, 28, 20, null, loc5);
            this._tfUnion3 = ObjCreate.createTextField(Language.getString(41625), 15, 50, 28, 20, null, loc5);
            this._tfCamp1 = ObjCreate.createTextField(GameDefConfig.instance.getECamp(1) + ":", 43, 50, 36, 20, this._spExtend, loc2);
            this._tfCamp2 = ObjCreate.createTextField(GameDefConfig.instance.getECamp(2) + ":", 43, 70, 36, 20, this._spExtend, loc3);
            this._tfCamp3 = ObjCreate.createTextField(GameDefConfig.instance.getECamp(3) + ":", 43, 90, 36, 20, this._spExtend, loc4);
            this._tfCamp1Score = ObjCreate.createTextField(Language.getStringByParam(41626, "0"), 80, 50, 75, 20, this._spExtend, loc1);
            this._tfCamp2Score = ObjCreate.createTextField(Language.getStringByParam(41626, "0"), 80, 70, 75, 20, this._spExtend, loc1);
            this._tfCamp3Score = ObjCreate.createTextField(Language.getStringByParam(41626, "0"), 80, 90, 75, 20, this._spExtend, loc1);
            this._tfCountdown = ObjCreate.createTextField(Language.getStringByParam(41697, "0", "0"), 23, 110, 115, 20, this._spExtend, loc1);
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnShowScore.addEventListener(flash.events.MouseEvent.CLICK, this.onClickShowScore);
            this._btnUp.addEventListener(flash.events.MouseEvent.CLICK, this.onClickUp);
            this._btnDown.addEventListener(flash.events.MouseEvent.CLICK, this.onClickDown);
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseDown);
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMoveBtnMouseUp);
            this.addEventListener(ViewEvent.Hide, this.onHide);
            Dispatcher.addEventListener(EventName.StageResize, this.stageResize);
            return;
        }

        /* internal */ /* var */_btnShowScore: GLoadedButton;

        /* internal */ /* var */_spMiniScore: Object /* flash.display.Sprite */;

        /* internal */ /* var */_spExtend: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfMyKill: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfMyHonor: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfUnion1: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfUnion2: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfUnion3: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp1: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp2: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp3: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp1Score: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp2Score: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCamp3Score: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCountdown: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnUp: GButton;

        /* internal */ /* var */_btnDown: GButton;

        /* internal */ /* var */_moveBtn: GButton;

        /* internal */ /* var */_endDate: Date;

        /* internal */ /* var */_secTimer: SecTimer;
    }
